//
//  HeaderViewController.m
//  reacticons
//
//  Created by Admin on 7/4/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "HeaderViewController.h"
#import "AppDelegate.h"
#import "ImageListViewController.h"
@implementation HeaderViewController
@synthesize delegate;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        NSMutableArray *recentlyAddedArray=[[NSMutableArray alloc] init];
        recentlyAddedArray=[[(AppDelegate*)[[UIApplication sharedApplication] delegate] dataManager] readRecentlyItemsWithType:@"recentlyAdded"];

        if (recentlyAddedArray) {
            if (recentlyAddedArray.count>0) {
                recentlyAdded=[[recentlyAddedArray objectAtIndex:0] retain];
            }
        }
        
        NSMutableArray *recentlyUsedArray=[[NSMutableArray alloc] init];

        recentlyUsedArray=[[(AppDelegate*)[[UIApplication sharedApplication] delegate] dataManager] readRecentlyItemsWithType:@"recentlyUsed"];
        
        if (recentlyUsedArray) {
            if (recentlyUsedArray.count>0) {
                recentlyUsed=[[recentlyUsedArray objectAtIndex:0] retain];
            }    
        }
        if (recentlyAdded) {
            recentlyAddedView =[[EGOImageView alloc] initWithFrame:CGRectMake(0, 2, 156, 116)];
            [recentlyAddedView setImageURL:[NSURL URLWithString:recentlyAdded.field3]];
            [recentlyAddedView setContentMode:UIViewContentModeScaleToFill];
        }
        if (recentlyUsed) {
            recentlyUsedView =[[EGOImageView alloc] initWithFrame:CGRectMake(162, 2, 156, 116)];
            [recentlyUsedView setImageURL:[NSURL URLWithString:recentlyUsed.field3]];
            [recentlyUsedView setContentMode:UIViewContentModeScaleToFill];
        }
        [self.view insertSubview:recentlyAddedView atIndex:0];
        [self.view insertSubview:recentlyUsedView atIndex:0];
        // sCustom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Buttons On Clicked

- (IBAction)buttonsOnClicked:(id)sender
{
    NSLog(@"buttonsOnClicked:%@",self.delegate);
    if ([self.delegate respondsToSelector:@selector(clickedHeaderBtn:)]) {
        NSLog(@"%d",[sender tag]);
        [self.delegate clickedHeaderBtn:sender];
    }
    

}

- (void)imageViewLoadedImage:(EGOImageView*)imageView{
    NSLog(@"egoimageview didload");
}
- (void)imageViewFailedToLoadImage:(EGOImageView*)imageView error:(NSError*)error{
        NSLog(@"egoimageview didfailed");
}

@end
